﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using SocialLearning;

namespace ArchitectureV2
{
    [DataContract]
    public class User
    {
        private I_UAC_Account user;
        private int userId;

        public User() { }

        public User(I_UAC_Account user, int id)
        {
            this.user = user; this.userId = id;
        }

        #region Basic Details

        [DataContract]
        public class BasicDetails
        {
            private I_UAC_BasicDetails user;

            public BasicDetails(I_UAC_BasicDetails user) { this.user = user; }

            [DataMember]
            public string Firstname { get { return (user == null ? null : user.Firstname); } set { } }

            [DataMember]
            public string Lastname { get { return (user == null ? null : user.Lastname); } set { } }

            [DataMember]
            public UAC_Gender Gender { get { return (user == null ? UAC_Gender.Unassigned : user.Gender); } set { } }

            [DataMember]
            public string ID { get { return (user == null ? null : user.ID); } set { } }

            [DataMember]
            public string Email { get { return (user == null ? null : user.Email); } set { } }

            [DataMember]
            public string Phone { get { return (user == null ? null : "not implemented"); } set { } }
        }

        [DataMember]
        public BasicDetails BasicAccountDetails { get { return (new BasicDetails(user.BasicAccountDetails)); } set { } }

        #endregion

        #region Advanced Details

        [DataContract]
        public class AdvancedDetails
        {
            private I_UAC_AdvancedDetails user;

            public AdvancedDetails(I_UAC_AdvancedDetails user) { this.user = user; }

            [DataMember]
            public string DateOfBirth { get { return (user == null ? null : user.DateOfBirth.ToString()); } set { } }

            [DataMember]
            public string HomeLanguage { get { return (user == null ? null : user.HomeLanguage); } set { } }

            [DataMember]
            public string Nationality { get { return (user == null ? null : user.Nationality); } set { } }

            [DataMember]
            public string HomeAddress { get { return (user == null ? null : user.HomeAddress); } set { } }

            [DataMember]
            public string PostalAddress { get { return (user == null ? null : user.PostalAddress); } set { } }

            [DataMember]
            public string City { get { return (user == null ? null : user.City); } set { } }

            [DataMember]
            public string Country { get { return (user == null ? null : user.Country); } set { } }

            [DataMember]
            public string Code { get { return (user == null ? null : user.Code); } set { } }

            [DataMember]
            public string MedicalAid { get { return (user == null ? null : user.MedicalAid); } set { } }

            [DataMember]
            public string MedicalAidNumber { get { return (user == null ? null : user.MedicalAidNumber); } set { } }

            [DataMember]
            public UAC_EthnicGroup EthnicGroup { get { return (user == null ? UAC_EthnicGroup.Other : user.EthnicGroup); } set { } }

            [DataMember]
            public UAC_Disabilities Disabilities { get { return (user == null ? UAC_Disabilities.None : user.Disabilities); } set { } }
        }

        [DataMember]
        public AdvancedDetails AdvancedAccountDetails { get { return (new AdvancedDetails(user.AdvancedAccountDetails)); } set { } }

        #endregion

        #region Marketing Details

        [DataContract]
        public class Marketing
        {
            private I_UAC_MarketingDetails user;

            public Marketing(I_UAC_MarketingDetails user) { this.user = user; }

            [DataMember]
            public string MarketingMedium { get { return (user == null ? null : user.MarketingMedium); } set { } }

            [DataMember]
            public string MarketingComment { get { return (user == null ? null : user.MarketingComment); } set { } }

            [DataMember]
            public string MarketingDateOfSubmission { get { return (user == null ? null : user.MarketingDateOfSubmission.ToString()); } set { } }

            [DataMember]
            public UAC_OccupationStatus CurrentStatus { get { return (user == null ? UAC_OccupationStatus.Unknown : user.CurrentStatus); } set { } }

            [DataMember]
            public string HighschoolDetails{ get { return (user == null ? null : user.HighschoolDetails); } set { } }
        }
        
        [DataMember]
        public Marketing MarketingDetails { get { return (new Marketing(user.MarketingDetails)); } set { } }

        #endregion

        #region Educational Background

        [DataContract]
        public class EducationalBackground
        {
            private I_UAC_EducationalBackground user;

            public EducationalBackground(I_UAC_EducationalBackground user) { this.user = user; }

            [DataMember]
            public InstitutionBackground[] Institution
            {
                get
                {
                    if (user == null || user.Institution == null) { return (null); }
                    List<InstitutionBackground> list = new List<InstitutionBackground>();
                    foreach (I_UAC_InstitutionBackground item in user.Institution)
                    {
                        list.Add(new InstitutionBackground(item));
                    }
                    return (list.ToArray());
                }
                set { }
            }

            [DataContract]
            public class InstitutionBackground
            {
                private I_UAC_InstitutionBackground user;

                public InstitutionBackground(I_UAC_InstitutionBackground user) { this.user = user; }

                [DataMember]
                public string InstitutionName { get { return (user == null ? null : user.InstitutionName); } set { } }

                [DataMember]
                public string StartDate { get { return (user == null ? null : user.StartDate.ToString()); } set { } }

                [DataMember]
                public string EndDate { get { return (user == null ? null : user.EndDate.ToString()); } set { } }
            }
        }

        [DataMember]
        public EducationalBackground EducationBackground { get { return (new EducationalBackground(user.EducationBackground)); } set { } }

        #endregion

        [DataMember]
        public int UserID { get { return (userId); } set { } }

        [DataMember]
        public string ProfilePicturePath { get { return ("C:\\profiles\\" + user.AccountUID + "\\userpic.bin"); } set { } }

        [DataMember]
        public string AccountUID { get { return (user.AccountUID); } set { } }

        [DataMember]
        public string SecretQuestion { get { return (user.SecretQuestion); } set { } }

        [DataMember]
        public bool ActiveStatus { get { return (user.Status); } set { } }

        [DataMember]
        public string Status { get { return ("not implemented"); } set { } }
    }
}